#include "vrouteAdapter.h"
#include "vroute.hpp"
#include "transContentErrorCode.h"

////////////////////////////////////////////////////////
///Notice: should directly call the mehtod in port manager not in vorute.
///in order to observe the old version, just call the method in vroute
////////////////////////////////////////////////////////
int vroute_start(){
	if(vroute::getInstance() == NULL){
		return E_TRANC_InsStateFailed;
	}
	return vroute::getInstance()->start();
}

int vroute_stop(){
	int result = vroute::getInstance()->stop();
	vroute::releaseInstance();
	return result;
}

///get a global unique port from stack
int vroute_getAPort(int timeout){
	return vroute::getInstance()->getAPort(timeout);
}

int vroute_getAPortSync(getPortCallback gcb){
	return vroute::getInstance()->getAPortSync(gcb);
}

///regist a port to global stack
int vroute_registPort(int port, int timeout){
	return vroute::getInstance()->registPort(port, timeout);
}

int vroute_registPortSync(int port, registPortCallback rgcb){
	return vroute::getInstance()->registPortSync(port, rgcb);
}

///set the port closing callback function
int vroute_setPortClosingCallback(int port, portClosingCallback pccb){
	return vroute::getInstance()->setPortClosingCallback(port, pccb);
}

portClosingCallback vroute_getPortClosingCallback(int port){
	return vroute::getInstance()->getPortClosingCallback(port);
}

int vroute_setPortClosingCallbackVid(vroute_t vid, portClosingCallback pccb){
	return vroute::getInstance()->setPortClosingCallbackVid(vid, pccb);
}
portClosingCallback vroute_getPortClosingCallbackVid(vroute_t vid){
	return vroute::getInstance()->getPortClosingCallbackVid(vid);
}

vroute_t vroute_bind(int port, int timeout){
	return vroute::getInstance()->bind(port, timeout);
}

int vroute_bind_sync(int port, bindSyncCallback bscb){
	return vroute::getInstance()->bind_sync(port, bscb);
}

int vroute_listen(vroute_t vid, int count){
	return vroute::getInstance()->listen(vid, count);
}

int vroute_accept(vroute_t vid, int timeout){
	return vroute::getInstance()->accept(vid, timeout);
}

int vroute_accept_sync(vroute_t vid, acceptSyncCallback ascb){
	return vroute::getInstance()->accept_sync(vid, ascb);
}

int vroute_recv(vroute_t vid, int flag, void* buffer, int bufferLen, int timeout){
	return vroute::getInstance()->receive(vid, flag, buffer, bufferLen, timeout);
}

int vroute_recv_sync(vroute_t vid, recvSyncCallback rscb){
	return vroute::getInstance()->receive_sync(vid, rscb);
}

int vroute_send(vroute_t vid, int flag, const void* buffer, int bufferLen, int timeout){
	return vroute::getInstance()->send(vid, flag, buffer, bufferLen, timeout);
}

int vroute_send_sync(vroute_t vid, int flag, const void* buffer, int bufferLen, sendSyncCallback sscb){
	return vroute::getInstance()->send_sync(vid, flag, buffer, bufferLen, sscb);
}

int vroute_sendTo(int localPort, const EndPoint* target, int flag, const void* buffer, int bufferLen, int timeout){
	return vroute::getInstance()->sendTo(localPort, target, flag, buffer, bufferLen, timeout);
}

int vroute_sendTo_sync(int localPort, const EndPoint* target, int flag, const void* buffer, int bufferLen, sendToSyncCallback stscb){
	return vroute::getInstance()->sendTo_sync(localPort, target, flag, buffer, bufferLen, stscb);
}

int vroute_receiveFrom(int localPort, int flag, void* buffer, int bufferLen, int timeout){
	return vroute::getInstance()->receiveFrom(localPort, flag, buffer, bufferLen, timeout);
}

int vroute_receiveFrom_sync(int localPort, receiveFromSyncCallback rfscb){
	return vroute::getInstance()->receiveFrom_sync(localPort, rfscb);
}

int vroute_getData(int port, char* buffer, int len){
	return vroute::getInstance()->getData(port, buffer, len);
}

int vroute_getLocalAddr(NodeAddr* nodeAddr){
	return vroute::getInstance()->getLocalAddr(nodeAddr);
}

int vroute_getRemoteAddr(vroute_t vid, NodeAddr* nodeAddr){
	return vroute::getInstance()->getRemoteAddr(vid, nodeAddr);
}

int vroute_tracertTarget(int port, int tracertType, const NodeAddr* target, NodeAddr* nodeList, int nodeCount, int timeout){
	return vroute::getInstance()->tracertTarget(port, tracertType, target, nodeList, nodeCount, timeout);
}

int vroute_tracertTarget_sync(int port, int tracertType, const NodeAddr* target, tarcertTargetCallback ttcb){
	return vroute::getInstance()->tracertTarget_sync(port, tracertType, target, ttcb);
}

int vroute_queryTarget(int port, int type, int valueLength, void* value, deviceInfo* result, int timeout){
	return vroute::getInstance()->queryTarget(port, type, valueLength, value, result, timeout);
}

int vroute_queryTarget_sync(int port, int type, int valueLength, void* value, queryTargetCallback qtcb){
	return vroute::getInstance()->queryTarget_sync(port, type, valueLength, value, qtcb);
}

int vroute_targetReachAble(int port, const NodeAddr* target, int timeout){
	return vroute::getInstance()->targetReachAble(port, target, timeout);
}

int vroute_targetReachAble_sync(int type, const NodeAddr* target, targetReachAbleCallback tracb){
	return vroute::getInstance()->targetReachAble_sync(type, target, tracb);
}

int vroute_setFixedNodeList(const NodeAddr* target, const NodeAddr* nodeList, int nodeCount){
	return vroute::getInstance()->setFixedNodeList(target, nodeList, nodeCount);
}

int vroute_close(vroute_t vid){
	return vroute::getInstance()->close_vid(vid);
}

int vroute_closePort(int port){
	return vroute::getInstance()->close_port(port);
}

int vroute_getVroutePort(vroute_t vid){
	return vroute::getInstance()->getVroutePort(vid);
}

int vroute_getErrorInfo(int errno_num, char* buffer, int bufferLen){
	return vroute::getInstance()->getErrorInfo(errno_num, buffer, bufferLen);
}

int vroute_connect(const EndPoint* target, int timeout, int localPort){
	return vroute::getInstance()->connect(target, timeout, localPort);
}

int vroute_connect_sync(const EndPoint* target, connectCallback ccb, int localPort){
	return vroute::getInstance()->connect_sync(target, ccb, localPort);
}

int vroute_isPortAlreadyExist(int port){
	return vroute::getInstance()->isPortAlreadyExist(port);
}
